import {formatSongTime,formatMsgTime} from './utils';

export default class Song {
  id: number;
  name: string;
  mvId: number;
  singer: [];
  album: {};
  alia: [];
  duration: string;
  url: string;
  vip: boolean;
  license: boolean;
  publishTime: string;
  constructor(params: any) {
    this.id = params.id;
    this.name = params.name;
    this.mvId = params.mvId;
    this.singer = params.singer;
    this.album = params.album;
    this.alia = params.alia;
    this.duration = params.duration;
    this.url = params.url;
    this.vip = params.vip;
    this.license = params.license;
    this.publishTime = params.publishTime;
  }
}

export function formatSongInfo(params: any) {
  return new Song({
    id: String(params.id),
    name: params.name,
    mvId: params.mv,
    singer: params.ar,
    album: params.al,
    alia: params.alia,
    vip: params.fee === 1,
    license: params.license,
    duration: formatSongTime(params.dt),
    url: `https://music.163.com/song/media/outer/url?id=${params.id}.mp3`,
    publishTime: formatMsgTime(params.publishTime),
  });
}
